home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / pyshared / Onboard / Pane.py < prev    next >
Encoding:
Python Source  |  2009-10-01  |  2.1 KB  |  62 lines

  1. class Pane:
  2.     "The pane holds the keys and is drawn by the keyboard widget."
  3.  
  4.     scale = (0, 0)
  5.     """ 
  6.     The amount to multiply to convert from layout co-ordinates to drawing
  7.     co-ordinates.
  8.     """
  9.  
  10.     def __init__(self, name, key_groups, columns, size, rgba):
  11.  
  12.         self.name = name
  13.         """ The name for this pane, needed when saving keyboard layout """
  14.  
  15.         self.size = size
  16.         """ The size of this pane as defined in the keyboard layout """ 
  17.  
  18.         self.rgba = rgba
  19.         """ 
  20.         Four tuple with values between 0 and 1 containing the pane's
  21.         background colour 
  22.         """
  23.  
  24.         self.columns = columns
  25.         """ A two dimensional array of Keys.  Used for scanning """
  26.  
  27.         self.key_groups = key_groups
  28.         """ 
  29.         Dictionary with group name as the key and an array of keys for each
  30.         value.  Each group of keys is drawn with the same label font size.
  31.         """
  32.  
  33.     def paint(self, context):
  34.         for group in self.key_groups.values():
  35.             for key in group:
  36.                 key.paint(self.scale, context)
  37.                 key.paint_font(self.scale, context)
  38.  
  39.     def on_size_changed(self, width, height, *args, **kargs):
  40.         self.scale = (width / self.size[0], height / self.size[1])
  41.  
  42.     def configure_labels(self, mods, *args, **kargs):
  43.         """
  44.         Cycles through each group of keys in this pane and set each key's
  45.         label font size to the maximum possible for that group.
  46.         """
  47.         for group in self.key_groups.values():
  48.             max_size = 0
  49.             for key in group:
  50.                 key.configure_label(mods, self.scale)
  51.                 best_size = key.get_best_font_size(self.scale, *args, **kargs)
  52.                 if not max_size or best_size < max_size:
  53.                     max_size = best_size
  54.             for key in group:
  55.                 key.font_size = max_size
  56.  
  57.     def get_key_at_location(self, location, *args, **kargs):
  58.         for group in self.key_groups.values():
  59.             for key in group:
  60.                 if key.point_within_key(location, self.scale, *args, **kargs):
  61.                     return key
  62.